package org.example.contract.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.contract.domain.ContractProduct;
import org.example.contract.service.IContractProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同产品表Controller
 *
 * @author heeenlin
 * @date 2024-04-12
 */
@Controller
@RequestMapping("/contract/contractProduct")
public class ContractProductController extends BaseController
{
    private String prefix = "contract/contractProduct";

    @Autowired
    private IContractProductService contractProductService;

    @GetMapping()
    public String contractProduct(String contractType ,ModelMap mmp)
    {
        mmp.put("contractType",contractType);
        return prefix + "/contractProduct";
    }

    /**
     * 查询合同产品表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractProduct contractProduct)
    {
        startPage();
        List<ContractProduct> list = contractProductService.selectContractProductList(contractProduct);
        return getDataTable(list);
    }

    /**
     * 导出合同产品表列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractProduct contractProduct)
    {
        List<ContractProduct> list = contractProductService.selectContractProductList(contractProduct);
        ExcelUtil<ContractProduct> util = new ExcelUtil<ContractProduct>(ContractProduct.class);
        return util.exportExcel(list, "合同产品表数据");
    }

    /**
     * 新增合同产品表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合同产品表
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractProduct contractProduct)
    {
        return toAjax(contractProductService.insertContractProduct(contractProduct));
    }


    /**
     * 修改保存合同产品表
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractProduct contractProduct)
    {
        return toAjax(contractProductService.updateContractProduct(contractProduct));
    }

    /**
     * 删除合同产品表
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractProductService.deleteContractProductByContractProductIds(ids));
    }
}
